<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 事件总线的方式
        vue3中没有，需要我们自己实现
    -->
    <div id="app">
        <son-a></son-a>
        <hr />
        <son-b></son-b>
    </div>
</body>

</html>
<script src="./vue.global.js"></script>
<script type="module">
    import eventBus from "./eventbusvue3.js"

    // 1、定义子组件A
    const SonA = {
        template: `
            <div>
                <h3>子组件A</h3>
                <input type="button" value="传" @click="chuanFn" />
            </div>
        `,
        methods: {
            chuanFn() {
                // 触发事件
                eventBus.publish("chuan", "hello,我是A组件");
            }
        }
    }

    // 2、定义子组件B
    const SonB = {
        template: `
            <div>
                <h3>子组件B</h3>
            </div>
        `,
        created() {
            // 绑定事件
            eventBus.subscribe("chuan", (str) => {
                console.log("B组件str", str);
            })
        }
    }

    const app = Vue.createApp({
        components: {
            SonA, SonB
        }
    });

    app.mount("#app");




</script>